<template>
  <div class="login">
    <p>
      用户名：
      <input type="text" v-model="loginForm.name" placeholder="用户名" />
    </p>
    <p>
      密码：
      <input type="password" v-model="loginForm.pass" placeholder="密码" />
    </p>
    <button @click="_login">登录</button>
  </div>
</template>
<script>
export default {
  name: "login",
  data() {
    return {
      loginForm: {
        name: "",
        pass: ""
      }
    };
  },
  methods: {
    _login() {
      if (this.loginForm.name === "" || this.loginForm.pass === "") {
        this.$message.warning("账号或密码不能为空");
      } else {
        this.$store
          .dispatch("user/_login", this.loginForm)
          .then(() => {
           
            this.$store.dispatch("user/_getInfo");
            let redirectUrl = decodeURIComponent(
              this.$route.query.redirect || "/"
            );
             console.log(redirectUrl)
            // 跳转到指定的路由
            this.$router.push({
              path: redirectUrl
            });
          })
          .catch(err => {
            console.log(err);
          });
      }
    }
  }
};
</script>